#include "one_dynamic.h"
#include <QDate>
#include <QPicture>

one_dynamic::one_dynamic(QWidget *parent) : QWidget(parent)
{
    /* 1.实例化 */
    topLay = new QHBoxLayout;
    buttomLay = new QHBoxLayout;
    layout = new QVBoxLayout;
    portraitLabel = new QLabel;
    nameLabel = new QLabel("测试用户");
    timeLabel = new QLabel(QDate::currentDate().toString());
    summaryLabel = new QLabel("大学之道，在明明德，在亲民，在止于至善。知止而后有定，定而后能静，静而后能安，安而后能虑，虑而后能得。物有本末，事有终始。知所先后，则近道矣。古之欲明明德于天下者，先治其国。欲治其国者，先齐其家。欲齐其家者，先修其身。欲修其身者，先正其心。欲正其心者，先诚其意。欲诚其意者，先致其知。致知在格物。物格而后知至，知至而后意诚，意诚而后心正，心正而后身修，身修而后家齐，家齐而后国治，国治而后天下平。自天子以至于庶人，壹是皆以修身为本，其本乱而末治者否矣。其所厚者薄，而其所薄者厚，未之有也。此谓知本，此谓知之至也。");
    photoLabel = new QLabel;
    praiseBtn = new QPushButton;
    praisePeopleLabel = new QLabel("测试用户2、测试用户3 觉得很赞");

    /* 2.设置头像 */
    portraitLabel->resize(35,35);
    QPixmap pixmap(":img/img/portrait.png");
    QPixmap img=pixmap.scaled(portraitLabel->size(),Qt::KeepAspectRatio);
    portraitLabel->setPixmap(img);

    photoLabel->resize(800,600);
    QPixmap photo(":img/img/bizhi.jpg");
    QPixmap img2=photo.scaled(photoLabel->size(),Qt::KeepAspectRatio);
    photoLabel->setPixmap(img2);

    praiseBtn->resize(40,40);
    QIcon icon;
    QPixmap picture(":img/img/praise_pushed.png");
    QPixmap p=picture.scaled(praiseBtn->size(),Qt::KeepAspectRatio);
    icon.addPixmap(p);
    praiseBtn->setIcon(icon);

    /* 3.设置布局 */
    portraitLabel->setObjectName("portraitLabel");
    portraitLabel->setMargin(5);
    nameLabel->setObjectName("nameLabel");
    topLay->setObjectName("topLay");
    this->setObjectName("dynamic_top");

    topLay->addWidget(portraitLabel);
    topLay->addWidget(nameLabel);
    topLay->addSpacing(50);
    topLay->addWidget(timeLabel);
    topLay->addStretch();
    this->setLayout(layout);
    layout->addLayout(topLay);
    layout->addWidget(summaryLabel);
    layout->addWidget(photoLabel);
    buttomLay->addWidget(praiseBtn);
    buttomLay->addWidget(praisePeopleLabel);
    buttomLay->addStretch();
    layout->addLayout(buttomLay);
    layout->addStretch();
    topLay->setSpacing(0);
    topLay->setMargin(0);             //设置外边距

    /* 4.设置样式 */
    summaryLabel->adjustSize();
    summaryLabel->setWordWrap(true);
    summaryLabel->setMargin(5);
    summaryLabel->setStyleSheet("font-size: 16px;");
    nameLabel->setStyleSheet("background-color:transparent;\
                              color:rgb(0, 0, 0);\
                              font-size: 16px;\
                              font-weight:75");
    praiseBtn->setStyleSheet("background-color:transparent;");
    praisePeopleLabel->setStyleSheet("color:rgb(39,88,150);");
    this->setContentsMargins(0,0,0,0);
}

one_dynamic::one_dynamic(struct DailySummary &dynamic)
{
    /* 1.实例化 */
    topLay = new QHBoxLayout;
    buttomLay = new QHBoxLayout;
    layout = new QVBoxLayout;
    portraitLabel = new QLabel;
    nameLabel = new QLabel(dynamic.DName);
    QString dateAndTime = dynamic.DDate.toString("yyyy-MM-dd dddd  ")+dynamic.DTime.toString("hh:mm:ss");
    timeLabel = new QLabel(dateAndTime);
    summaryLabel = new QLabel(dynamic.DContent);
    photoLabel = new QLabel;
    praiseBtn = new QPushButton;
    praisePeopleLabel = new QLabel(dynamic.DPraise+"......");

    /* 2.设置头像 */
    portraitLabel->resize(35,35);
    QPixmap pixmap(":img/img/portrait.png");
    QPixmap img=pixmap.scaled(portraitLabel->size(),Qt::KeepAspectRatio);
    portraitLabel->setPixmap(img);

    photoLabel->resize(800,600);
    //QPixmap photo(":img/img/bizhi.jpg");
    QPixmap img2=dynamic.DPicture.scaled(photoLabel->size(),Qt::KeepAspectRatio);
    photoLabel->setPixmap(img2);

    praiseBtn->resize(40,40);
    QIcon icon;
    QPixmap picture(":img/img/praise_pushed.png");
    QPixmap p=picture.scaled(praiseBtn->size(),Qt::KeepAspectRatio);
    icon.addPixmap(p);
    praiseBtn->setIcon(icon);

    /* 3.设置布局 */
    portraitLabel->setObjectName("portraitLabel");
    portraitLabel->setMargin(5);
    nameLabel->setObjectName("nameLabel");
    topLay->setObjectName("topLay");
    this->setObjectName("dynamic_top");

    topLay->addWidget(portraitLabel);
    topLay->addWidget(nameLabel);
    topLay->addSpacing(50);
    topLay->addWidget(timeLabel);
    topLay->addStretch();
    this->setLayout(layout);
    layout->addLayout(topLay);
    layout->addWidget(summaryLabel);
    layout->addWidget(photoLabel);
    buttomLay->addWidget(praiseBtn);
    buttomLay->addWidget(praisePeopleLabel);
    buttomLay->addStretch();
    layout->addLayout(buttomLay);
    layout->addStretch();
    topLay->setSpacing(0);
    topLay->setMargin(0);             //设置外边距

    /* 4.设置样式 */
    summaryLabel->adjustSize();
    summaryLabel->setWordWrap(true);
    summaryLabel->setMargin(5);
    summaryLabel->setStyleSheet("font-size: 16px;");
    nameLabel->setStyleSheet("background-color:transparent;\
                              color:rgb(0, 0, 0);\
                              font-size: 16px;\
                              font-weight:75");
    praiseBtn->setStyleSheet("background-color:transparent;");
    praisePeopleLabel->setStyleSheet("color:rgb(39,88,150);");
    this->setContentsMargins(0,0,0,0);
}

